
%% Dynamic Factor Model for Mixed Frequency Data
% With Time-Varying Intercepts and Stochastic Volatility
% Decomosition long-run hours and long-run productivity

clear
clc

addpath('functions');
addpath('data');
 
seed = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(seed);


%% Settings

% Data Location and Adjustments


settings.panelsize = 28;

settings.remove_means = 1;
settings.standardise = 0;                               % Standardise all Variables Prior to estimation (optional)
settings.remove_outliers = 1;                           % Remove outliers following Stock and Watson (reccommended)

% Model Specification


settings.WhereAnnual = [];
settings.WhereQuartYoY = [];
settings.WhereQuarterly = [1:4];
settings.soft12 = [];                                   % Specify position of soft variables starting from the beggining; if none, leave blank
settings.soft6 = [];
settings.soft3 = [];

settings.constant = 0;                                  % Add constant in VAR
settings.exog = [];                                     % Specify Position of Exogenous Variables (optional);

settings.nf = 1;                                        % Number of latent factors

settings.p = 2;                                         % Maximum lag order of factor VAR
settings.s = 0;                                         % Maximum factor lags that load observables (0 = contemporaneous only)
settings.q = 2;                                         % Order of serial correlation in idiosyncratic components. Max = 5;

settings.vardiag = 0;

settings.h = 0;                                        % Desired forecast horizon


settings.include_trend = [];                    % Include trend in variables with coef unrestricted

settings.SV_factors = 1;                                % Add Stochastic Volatility to the common factors (0 = no; 1 = yes);
settings.SV_idiosyncratic = 1;
                         
                              
% Gibss Sampler Setting

settings.nreps = 7000;       % Number of Gibbs Sampler Draws
settings.nburn = 2000;       % Discard the first nburn draws as Burn-in Draws

settings.show_plots = 0;
settings.plot_each = 20;

%% Bayesian Priors

settings.var_priors = 0;     % 0 = Noninformative; 1 = Independent N-IW;
settings.lambda_priors = 0;   % 0 = Noninformative; 1 = shrink towards zero
settings.rho_priors = 0;     % 0 = Noninformative; 1 = shrink towards zero

settings.prior_SV = 0.0001;
settings.prior_SV_sm = 0.0001;


%% Run DFM for Baseline Case

settings.trend = 2;
settings.schemenumber = 202;
% settings.prior_trend = 0.001./(3.*[80*(1.5^2) 70*(0.75^2) 10]);
% settings.prior_trend = repmat(0.001/3,1,3);
settings.prior_trend = 0.001/2;

load('ADP_baseline.mat')

[results] = DFM_function3_Simple(settings,yraw,dates,datenum(now));

save('output\results_Figure4','results','settings')


